package tsing.javase.common.enums;

/**
 * @Author Tsing/吴清平
 * @Date 2022/10/18 15:41
 * @Version 1.0
 */
public enum ResultCode {

    /* 成功状态码 */
    SUCCESS(0, "成功"),
    RESULE_NONE_DATA(20001, "数据库中无数据"),
    ERROR(1,"失败"),
    /* 参数错误：10001-19999 */
    PARAM_IS_BLANK(9170, "调用能力共享平台接口参数缺失"),
    AOP_ORDER_ERROR(9171, "调用能力共享平台接口失败"),
    AOP_PARAMS_ERROR(9172, "tb_sp_info未配置AOP能力平台关联"),
    AOP_USERID_ERROR(9173, "userid解析省份地市异常"),
    AOP_APIRESULT_ERROR(9174, "调用能力共享平台接口未返回成功码"),
    AOP_CHANNEL_ERROR(9175, "TB_AOPCANCEL_CONFIG未配置AOP能力平台关联"),
    AOP_ECB_ERROR(9176, "调用ECB接口失败"),
    H5_CANCELORDER_ERROR(9177, "调h5的退订接口失败"),
    CAP_ORDER_ERROR(9171, "调用CAP查询接口失败"),
    PARAM_IS_INVALID(8002, "参数无效"),
    PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
    PARAM_NOT_COMPLETE(10004, "参数缺失"),

    PARAM_FILE_FORMAT(10005, "文件格式不对"),
    PARAM_FILE_IOEX(10006, "文件读取异常");

    public Integer code;

    public String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getMessage(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static String getMessage(ResultCode resultCode){
        return resultCode.message;
    }



    public static Integer getCode(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }



    @Override
    public String toString() {
        return this.name();
    }


    public static void main(String[] args) {
        ResultCode success = ResultCode.SUCCESS;
        System.out.println(success.message);
    }
}
